package com.yootk;
import java.util.concurrent.TimeUnit;
public class YootkDemo {
   public static int money = 0;
    public static void main(String[] args) throws Exception {
        int[] data = {100, 200, 300};
        Thread[] threads = new Thread[data.length];

        for(int x = 0; x < data.length; x++) {
            final int temp = x;
            threads[x] = new Thread(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(100);

                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    money += data[temp];
                }
            });
            threads[x].start();
        }

        // 等待所有线程执行完成
        for(Thread thread : threads) {
            thread.join();
        }

        TimeUnit.SECONDS.sleep(1);
        System.out.println("【计算完成】最终存款总额：" + money);
    }
}
